import { defineConfig } from "rollup";
import { dts } from "rollup-plugin-dts";
// import typescript from '@rollup/plugin-typescript'
import typescript from 'rollup-plugin-typescript2'
import resolve from '@rollup/plugin-node-resolve';
export default defineConfig([
  {
    input: [
      'src/index.ts'
    ],
    output: [
      {
        // dir: 'dist', // 目标目录
        file: 'dist/index.cjs', // 输出文件名
        format: "cjs",
        // sourcemap: true
      },
      {
        // dir: 'dist',
        file: 'dist/index.js',
        format: "esm",
        // sourcemap: false
      },
    ],
    plugins: [
      typescript(),
      resolve(),
      // typescript({ compilerOptions: { lib: ["es5", "es6", "dom"], target: "es5", outDir: 'dist' } })
    ]
  },
  {
    input: 'src/index.ts',
    output: [{ file: "./index.d.ts", format: "es" }],
    plugins: [
      dts(),
    ],
  },

  /**
   * node
   */
  {
    input: [
      'src/utils/node.ts'
    ],
    output: [
      {
        file: 'dist/node/index.cjs', // 输出文件名
        format: "cjs",
      },
      {
        file: 'dist/node/index.js',
        format: "esm",
      },
    ],
    plugins: [
      typescript(),
    ]
  },
  {
    // "module": "NodeNext",
    // "moduleResolution": "NodeNext",
    input: 'src/utils/node.ts',
    output: [{ file: "dist/node/index.d.ts", format: "es" }],
    plugins: [
      dts(),
    ],
  },

  /**
   * esm
   */
  {
    input: [
      'src/utils/esm.ts'
    ],
    output: [
      {
        file: 'dist/esm/index.cjs', // 输出文件名
        format: "cjs",
      },
      {
        file: 'dist/esm/index.js',
        format: "esm",
      },
    ],
    plugins: [
      typescript(),
    ]
  },
  {
    input: 'src/utils/esm.ts',
    output: [{ file: "dist/esm/index.d.ts", format: "es" }],
    plugins: [
      dts(),
    ],
  },

  /**
   * browser
   */
  {
    input: [
      'src/utils/browser.ts'
    ],
    output: [
      {
        file: 'dist/browser/index.cjs', // 输出文件名
        format: "cjs",
      },
      {
        file: 'dist/browser/index.js',
        format: "esm",
      },
    ],
    plugins: [
      typescript(),
      resolve(),
    ]
  },
  {
    input: 'src/utils/browser.ts',
    output: [{ file: "dist/browser/index.d.ts", format: "es" }],
    plugins: [
      dts(),
    ],
  },



  // ==============
  // {
  //   input: 'src/index.ts',
  //   output: {
  //     file: 'dist/esm/index.js',
  //     format: "esm",
  //     sourcemap: false
  //   },
  //   plugins: [
  //     typescript()
  //   ]
  // },
  // {
  //   input: 'src/index.ts',
  //   output: {
  //     file: 'dist/browser/index.js',
  //     format: "iife",
  //     name: "peakUtils",
  //     sourcemap: true,
  //   },
  //   plugins: [
  //     typescript()
  //   ]
  // }
])

